from rest_framework import serializers
from user.userser import JobInfoSerializer
from home.models import Jobposting,DeliverJobposting
from home.homeser import JobpostingSerializer,JobpostingSer
from job.models import Interview


# 投递记录表 关联职位信息
class DeliverJobpostingSer(serializers.ModelSerializer):
    jobinfo=JobInfoSerializer()
    jobposting = JobpostingSerializer()
    class Meta:
        model = DeliverJobposting
        fields = '__all__'

class DeliverJobSer(serializers.ModelSerializer):
    jobinfo=JobInfoSerializer()
    jobposting = JobpostingSer()
    class Meta:
        model = DeliverJobposting
        fields = '__all__'

class InterviewSer(serializers.ModelSerializer):
    class Meta:
        model = Interview
        fields = '__all__'

class InterviewSerializer(serializers.ModelSerializer):
    deliverjob = DeliverJobpostingSer()
    class Meta:
        model = Interview
        fields = '__all__'


# class DelJobpostingSer(serializers.ModelSerializer):
#     # 嵌套求职者信息
#     jobinfo = serializers.SerializerMethodField()
#     # 嵌套初筛结果摘要
#     interview_summary = serializers.SerializerMethodField()
#
#     class Meta:
#         model = DeliverJobposting
#         fields = ['id', 'jobposting_id', 'jobinfo', 'interview_summary']
#     def get_jobinfo(self, obj):
#         # 返回求职者详细信息
#         jobinfo = obj.jobinfo
#         return {
#             "id": jobinfo.id,
#             "name": jobinfo.name,
#             "aveter": jobinfo.aveter,
#             "resume_url": jobinfo.resume_url,
#             "education": jobinfo.education,
#             "description": jobinfo.description,
#             "user_id": jobinfo.user_id  # 用于后续聊天功能
#         }
#     def get_interview_summary(self, obj):
#         interview = obj.interview
#         if not interview:
#             return None  # 如果没有面试记录，返回 None 或者空字典
#         return {
#             "ai_match_score": interview.ai_match_score,
#             "ai_search_score": interview.ai_search_score,
#             "ai_match_points": interview.ai_match_points,
#             "ai_risk_points": interview.ai_risk_points,
#             "user_evaluation": interview.user_evaluation,
#             "hr_evaluation": interview.hr_evaluation,
#             "end_at": interview.end_at.strftime("%Y-%m-%d %H:%M:%S") if interview.end_at else None,
#             "passed": interview.ai_search_score >= 0.5
#         }
#
#
